package com.bjgov.scoresys.util;

import java.io.StringWriter;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;


public class TemplateUtil {
	private ConcurrentHashMap<String,Template> cache = null;

	private TemplateUtil() {
		cache = new ConcurrentHashMap<String,Template>();
	}

	public static Template getTemplate(String tempName) throws Exception{
		return Velocity.getTemplate(tempName);
	}

	public static String getOutput(VelocityContext context, String templateName) throws Exception{
		StringWriter writer = new StringWriter();
		TemplateUtil.getTemplate(templateName).merge(
				context, writer);
		return writer.toString();
	}
}